package models

import (
	"github.com/astaxie/beego/orm"
)

type PreferenceImage struct {
	Id      int64 `orm:"pk;auto"`  // 项目ID
	ImageId int64 `orm:"size(11)"` // 项目父级ID
}

func (m *PreferenceImage) TableName() string {
	return "preference_image"
}

// 获取全部用户
func (m *PreferenceImage) GetPreferenceUser() []*PreferenceImage {
	list := make([]*PreferenceImage, 0)
	_, _ = m.Query().All(&list)
	return list
}
func (m *PreferenceImage) GetPreferenceLists() []map[string]interface{} {
	list := make([]*PreferenceImage, 0)
	_, _ = m.Query().All(&list)
	resTree := make([]map[string]interface{}, 0)
	for _, citem := range list {
		cres := PerferenceImageJson(citem)
		resTree = append(resTree, cres)
	}
	return resTree
}

// 查询方法
func (m *PreferenceImage) Query() orm.QuerySeter {
	return orm.NewOrm().QueryTable(m)
}

// 添加用户
func (m *PreferenceImage) Insert() error {
	_, err := orm.NewOrm().Insert(m)
	return err
}

// 删除用户
func (m *PreferenceImage) Delete() error {
	_, err := orm.NewOrm().Delete(m)
	return err
}

// 修改用户信息
func (m *PreferenceImage) Update(fields ...string) error {
	_, err := orm.NewOrm().Update(m, fields...)
	return err
}
func (m *PreferenceImage) Read(fields ...string) (int64, error) {
	if err := orm.NewOrm().Read(m, fields...); err != nil {
		return 0, err
	}
	return m.Id, nil
}
func (m *PreferenceImage) GetPreferenceImageById(id int64) (*PreferenceImage, error) {
	err := m.Query().Filter("id", id).One(m)
	return m, err
}
